package com.malotur.test.fft;

public class Bayes {
//	float[] x_bins = new float[] { 1.0f, 2.3f, 2.5f, 10.0f };
	float[] x_bins = new float[] { 1.5f, 3.3f, 3.7f, 15.0f };
	int n_bins = x_bins.length;
	float[] p_x_a = new float[] { 0.1f, 0.8f, 0.1f };
	float[] p_x_not_a = new float[] { 0.33f, 0.33f, 0.33f };

	public float calcBayes(float x, float prior) {
		int k = -1;
		float prob = 0.0f;
		for (int i = 0; i < n_bins; i++) {
			if (x < x_bins[i + 1] && x >= x_bins[i]) {
				k = i;
				break;
			}
		}
		
		if (k >= 0)
			prob = p_x_a[k] * prior / (p_x_a[k] * prior + p_x_not_a[k] * (1 - prior));
			if(prob == 0.0f)
				prob = 0.00001f;
		return prob;
	}
}
